using System;
using System.Collections.Generic;
using System.ComponentModel;
using OpenFlashChartLib.Json;

namespace OpenFlashChartLib.Charts
{
    public class YAxis : Axis
    {
        private int offset;
        private IList<string> _labels;

        public YAxis()
        {
        }

        [JsonProperty("tick-length")]
        [DefaultValue(0)]
        public int TickLength { get; set; }

        [JsonProperty("offset")]
        [DefaultValue(0)]
        public int Offset
        {
            get { return offset; }
            set { offset = value > 0 ? 1 : 0; }
        }

        [JsonProperty("labels")]
        public IList<string> Labels
        {
            get
            {
                if (_labels == null)
                    _labels = new List<string>();
                return _labels;
            }
            set
            {
                _labels = value;
            }
        }

        /// <summary>
        /// Tells serializer if the y labels should be serialized
        /// </summary>
        public bool LabelsSpecified
        {
            get { return _labels != null; }
        }

        public override bool IsSpecified()
        {
            return LabelsSpecified || Offset != 0 || TickLength != 0 || base.IsSpecified();
        }

        public void SetRange(double min, double max)
        {
            Max = Math.Ceiling(max);
            Min = Math.Floor(min);
        }

        public void SetRange(double min, double max, int step)
        {
            Max = Math.Ceiling(max);
            Min = Math.Floor(min);
            Steps = step;
        }
    }
}